
proc highlight_module {args} {
	parse_proc_arguments -args $args pargs
	remove_colors
	if {[info exists pargs(-macro)] && [$pargs(-macro) ne ""]} {
		set all_blocks $pargs(-macro)
	} else {
		set all_blocks [get_attr [get_flat_cells -filter is_hard_macro]  full_name ]
	}

	if {[info exists pargs(-level)] && [$pargs(-level) ne ""]} {
		set level $pargs(-level)
	} else { 
		set level 3
	}
	if {[info exists pargs(-all)] && [$pargs(-all) == 1]} {
		set all 1 } else {set all 0}

	set hier_list {}
	foreach block $all_blocks {
		lappend hier_list [join [lrange [split $block /] 0 [expr $level - 1] ] / ]
	}
	set hier_list [lsort -u $hier_list]
	set hier_num [llength $hier_list]
	for {set i 0} {$i < $hier_num} {incr i} {
		set cur_hier [lindex $hier_list $i]
		echo $cur_hier
		if {$all == 1} {
			change_selection [get_flat_cells -filter "full_name =~ $cur_hier*"]
		} else {
			change_selection [get_flat_cells -filter "full_name =~ $cur_hier* && is_hard_macro"]
		}
		set_colors -cycle_color [gs]
		change_selection ""
	}
	if {[info exists pargs(-output_file)] && $pargs(-output_file) != ""} {
		sh rm -rf tmp.tcl
		foreach hier $hier_list {
			set output($hier) [get_attr [get_flat_cells -filter "full_name =~ $cur_hier* && is_hard_macro"] full_name]
			echo "#" >> tmp.tcl
			foreach m $output($hier) {
				echo $m >> tmp.tcl
			}
		}	
		sh mv tmp.tcl $pargs(-output_file)
	}
}

define_proc_attributes highlight_module -info "highlight macros using different color" \
	-define_args \
	{
		{-macro "Specify the macros you want to colorize.Default is all macro." "macro_name" string optional}
		{-level "Specify the hierarchy level.Default is 3." 3 int optional}
		{-output_file "Output file for macro groups by different color.Defalut is empty." "file_path" string optional}
		{-all "Highlight both macro and standard cell.Default is 0" "0" string optional}	
	}
